package com.samphanie.auiu.admin.domain.vo;

import com.samphanie.auiu.common.dto.RoleDto;
import com.samphanie.auiu.common.dto.UserProfileDto;
import lombok.*;

import java.io.Serializable;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author ZSY
 * @email 1451691457@qq.com
 */
@Data
@With
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AdminVo implements Serializable {
    private static final long serialVersionUID = 1426149201011983558L;

    private Long id;
    private String username;
    private String nickname;
    private String avatar;
    private String mobile;
    private String email;
    private boolean enabled;
    private boolean usingMfa;
    private Set<String> access;

    public static Function<UserProfileDto, AdminVo> fromUser = (user) -> AdminVo.builder()
            .id(user.getId())
            .username(user.getUsername())
            .nickname(user.getNickname())
            .avatar(user.getAvatar())
            .email(user.getEmail())
            .mobile(user.getMobile())
            .access(user.getRoles().stream()
                    .map(RoleDto::getRoleName)
                    .collect(Collectors.toSet()))
            .build();

}
